#!/bin/bash
echo pwd
echo "======== begin pull source code from github 获取仓库代码===>>"
git pull
sleep 1

#echo "======== execute maven === "
#mvn clean package -DskipTests
##定义应用镜像
APP_IMAGE="dockerdemo_img0"
APP_CONTAINER="dockerdemo_img0_c0"

docker container stop ${APP_CONTAINER}
echo "==============stop container success======"
sleep 1

#docker container rm -f ${docker container ls -q --filter ancestor='$'${APP_IMAGE}}
docker container rm -f ${APP_CONTAINER}
echo "==============rm container success!!============="
sleep 1

docker image rm ${APP_IMAGE}
echo "==============rm image success!! 删除镜像成功 ===>>>"
sleep 2

echo " begine to build image of your java app,开始构建镜像"
docker image build -t ${APP_IMAGE} .
echo "==============docker build image success!! 构建镜像成功 ==>>>"

sleep 2

docker container run --name  ${APP_CONTAINER} -it -p 8080:8080 ${APP_IMAGE} sh
echo"==============start docker container success!! 容器启动成功===>>>"
sleep 1

#docker container ls



